#include<stdio.h>
struct s
{
	char name[20];
	int age;
};
void change(char*p1,char*p2,size_t wide)
{
	int i = 0, j = 0;
	char temp = 0;
	for (i = 0; i < wide; i++)
	{
		temp = *p1;
		*p1 = *p2;
		*p2 = temp;
		p1++;
		p2++;
	}
}
int compare(void* p1, void* p2)
{
	return 	strcmp(((struct s*)p1)->name, ((struct s*)p2)->name);
}
void copyqsort(void* base, size_t num, size_t wide, int (*compare)(void* p1, void* p2))
{
	int i = 0, j = 0;
	for (i = 0; i < num - 1; i++)
	{
		for (j = 0; j < num - 1 - i; j++)
		{
			if (compare((char*)base + j * wide,(char*)base + (j + 1) * wide)>0)
			{
				change((char*)base+j*wide,(char*)base+(j+1)*wide,wide);
			}
		}
	}
}
int main()
{
	//int arr[10] = { 9,1,2,8,3,7,4,6,5,10 };
	struct s arr[3] = { {"zhangsan",100},{"lisi",25},{"wangwu",50} };
	int num = 0, wide = 0, i = 0;
	num = sizeof(arr) / sizeof(arr[0]);
	wide = sizeof(arr[0]);
	copyqsort(arr, num, wide, compare);
	for (i = 0; i < num; i++)
	{
		printf("%s %d\n", arr[i].name, arr[i].age);
	}
	return 0;
}
